package com.catmiao.spark.test

import java.io.ObjectOutputStream
import java.net.Socket

/**
 * @title: Executor
 * @projectName spark_study
 * @description: TODO
 * @author ChengMiao
 * @date 2024/1/11 14:41
 */
object Driver {

  def main(args: Array[String]): Unit = {

    val client1 = new Socket("localhost", 9999)
    val client2 = new Socket("localhost", 8888)

    val out1 = client1.getOutputStream
    val out2 = client2.getOutputStream


    val stream1 = new ObjectOutputStream(out1)
    val stream2 = new ObjectOutputStream(out2)

    val task = new Task

    val subTask1 = new SubTask
    subTask1.datas = task.datas.take(2)
    subTask1.logic = task.logic

    val subTask2 = new SubTask
    subTask2.datas = task.datas.takeRight(2)
    subTask2.logic = task.logic
    // 发送数据
    stream1.writeObject(subTask1)
    stream2.writeObject(subTask2)

    stream1.flush()
    stream1.close()
    stream2.flush()
    stream2.close()

    client1.close()
    client2.close()

  }

}
